package org.yenn.pattern;

import org.yenn.pattern.utils.CodeUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "codeServlet", value = "/code-servlet")
public class CodeServlet extends HttpServlet {


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        request.setCharacterEncoding("UTF-8");

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
        //获取姓名
        String username = request. getParameter( "username");
        System.out.println("username="+username);

        //获取爱好
        String[] hobbys = request . getParameterValues ( "hobby");
        for(String ho:hobbys) {
            System.out.println("ho="+ho);

        }


        // Hello
        System.out.println(response.getCharacterEncoding());
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1> UTF-8:" + username + "</h1>");
        out.println("<h1>ISO:" + CodeUtil.convertIso(username) + "</h1>");
        out.println("<h1>GBK:" + CodeUtil.convertGBK(username) + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
    }
}